#!/bin/sh
#
# 简单写一下脚本的功能。
#
#
#

if [ $# -ne 1 ]; then
	echo "Usage: mdfile."
	exit
fi

source config

sed -e "s/。/。\n/g" $1|grep "[1234567890]年" |awk '{print $0 }' |sed -e "/^[# (\[]/d" | awk '{split($0,a,"[^0-9]+"); for(i in a) {printf a[i]"年"};printf ":::";print $0}'|tr -s '年'|sed -e "s/\*//g"| sed -e "s/:::/\t\"/g" |sed -e "s/$/\"/g" |sed -e "s/(/（/g"|sed -e "s/)/）/g" | sed -e "s/>//g" | sed -e "s/'//g" |sed -e "s/^/splityear /g" >tmp.md

sh tmp.md >timeline.md

awk -v bn=$bookname '{print $0 "《"bn"》"}' timeline.md |sort -g > timeline.md.1

sort -g timeline.md.1 >timeline.md

if [ -e config ]; then 

	source config

	echo "%" $bookname"时间线" > index_timeline.md

	echo "%" "hbaolong@vip.qq.com" >> index_timeline.md

	echo "" >> index_timeline.md

	commcode bookheader >>index_timeline.md

	echo "" >> index_timeline.md

	awk '{print $0 "\n"}' timeline.md >> index_timeline.md 

	pandoc -s index_timeline.md -o index_timeline.html 

fi

rm -f tmp.md timeline.md.1 
